using UnityEngine;

public class StoneGolemAnimator : FormAnimator {

    #region Properties
    public float Speed {
        get { return AnimatorComponent.GetFloat("Speed"); }
        set { AnimatorComponent.SetFloat("Speed", value); }
    }
    #endregion

    void OnDisable() {
        AnimatorComponent.ResetTrigger("Attack");
    }

   protected override void ConnectedFormController(FormController controller) {
        base.ConnectedFormController(controller);

        PlayerInput input = controller.GetComponent<PlayerInput>();
        input.OnMovementVerticalMagnitude.AddListener(s => Speed = s);
        input.OnAttack.AddListener(Attack);
    }

    void Attack() {
        if(gameObject.activeInHierarchy && !AnimatorComponent.GetCurrentAnimatorStateInfo(0).IsName("Left Punch") && !AnimatorComponent.GetCurrentAnimatorStateInfo(0).IsName("Right Punch") && !AnimatorComponent.GetCurrentAnimatorStateInfo(0).IsName("Hand Idle")) {
            if(!AnimatorComponent.GetBool("Attack")) {
                AnimatorComponent.SetTrigger("Attack");
                AnimatorComponent.SetBool("LeftRightHand", !AnimatorComponent.GetBool("LeftRightHand"));
            }
        }
    }
}